package com.soxing.braindata.service.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.soxing.braindata.dao.domain.request.ExperimentSearchRequest;
import com.soxing.braindata.dao.domain.request.SearchRequest;
import com.soxing.braindata.dao.entity.Experiment;
import com.soxing.braindata.dao.service.IExperimentService;
import com.soxing.common.utils.util.ObjectMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author :durango
 * @date :2022/7/2 20:12
 * @description 课题实验管理实现
 */
@Service
public class ExperimentManagerImpl extends AbstractManager<Experiment> implements IExperimentManager {
    @Resource
    private IExperimentService experimentService;

    @Override
    public IService<Experiment> getService() {
        return experimentService;
    }

    @Override
    public LambdaQueryWrapper<Experiment> wrapSearchRequest(SearchRequest request) {
        ExperimentSearchRequest searchRequest = (ExperimentSearchRequest) request;
        if (request == null) {
            searchRequest = new ExperimentSearchRequest();
        }
        Experiment obj = ObjectMapper.map(searchRequest, Experiment.class);
        LambdaQueryWrapper<Experiment> queryWrapper = new LambdaQueryWrapper<>(obj).orderByAsc(Experiment::getExperimentOrder);
        return queryWrapper;
    }
}
